package org.gjw.controller;

import org.gjw.service.SysUserService;
import org.gjw.util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author guojunwang
 * @date 2021-06-27 15:42
 */
@RestController
public class TestController {

    @Autowired
    private SysUserService sysUserService;

    @PreAuthorize("hasAnyAuthority('aa')")
    @GetMapping("/test")
    public String test(){
        return "test";
    }


    @GetMapping("/getToken")
    public String getToken( Integer id ){
        JwtUtil jwtUtil = new JwtUtil();
        return jwtUtil.generateToken( sysUserService.getById(id));
    }

    @GetMapping("/toBaidu")
    public void toBaidu(HttpServletResponse response) throws IOException {
        response.sendRedirect("http://www.baidu.com");
    }

}
